<?php
include_once 'Connection.php';

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of TabelaBanco
 *
 * @author Gustavo
 */
class TabelaBanco {
    //put your code here
    var $Field;
    var $Type;
    var $Null;
    var $Key;
    var $Default;
    var $Extra;
   
    
    public function recuperaCamposTabela(TabelaBanco $tabelaBanco, $nmTabela){
            $consulta = "show columns from $nmTabela";
            $resultado = Connection::consultasSql($consulta);
            
            while ($tabelaBanco = mysql_fetch_object($resultado,'TabelaBanco')){ 
                $lista[] = $tabelaBanco;
                
                /*
                echo $tabelaBanco->Field."<br>";
                echo $tabelaBanco->Default."<br>";
                echo $tabelaBanco->Extra."<br>";
                echo $tabelaBanco->Key."<br>";
                echo $tabelaBanco->Null."<br>";
                echo $tabelaBanco->Type."<br>";
                 * 
                 */
            }
            
            foreach($lista as $tabela){
                if(stristr($tabela->Field,'id') && $tabela->Key == 'PRI'){
                    $campos[0] = $tabela->Field;
                }  elseif (stristr($tabela->Field,'id')) {
                    $campos[0] = $tabela->Field;
                }
                
                if(stristr($tabela->Field,'desc') && stristr($tabela->Type,'varchar')){
                    $campos[1] = $tabela->Field;
                }  elseif (stristr($tabela->Type,'varchar')) {
                    $campos[0] = $tabela->Field;
                }
                
                
                
            }
           
            return($campos);
            
    }
}

?>
